package com.flmz.friend.rabbitmq;

import com.flmz.api.domain.dto.JudgeSubmitDTO;
import com.flmz.common.core.constants.RabbitMQConstants;
import com.flmz.common.core.enums.ResultCode;
import com.flmz.common.security.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class JudgeProducer {

	@Autowired
	private RabbitTemplate rabbitTemplate;

	public void produceMsg(JudgeSubmitDTO judgeSubmitDTO) {
		try {
			// 生成消息放到mq中
			rabbitTemplate.convertAndSend(RabbitMQConstants.OJ_WORK_QUEUE, judgeSubmitDTO);
		} catch (Exception e) {
			log.error("生产者发送消息异常", e);
			throw new ServiceException(ResultCode.FAILED_RABBIT_PRODUCE);
		}
	}
}